current_path=`pwd`

username=`whoami`
myenv_home=/home/$username/.devkit.myenv

data_path=$1
if [ "$1" == "" ]; then
    data_path=/home/$username
    echo 'WARNING: 数据目录将会创建为 $data_path'
    echo 'HINT: 重新 sh setup.sh DATAPATH 覆盖即可。'
fi


if [ ! -d "$myenv_home" ]; then
    echo "创建文件夹: $myenv_home"
    mkdir -p "$myenv_home"
fi



# 1 prepare myenv.source.base
myenv_source=$myenv_home/myenv.source
echo "export MYENV=$myenv_home"                                               > $myenv_source
echo "export DATAPATH=$data_path"                                            >> $myenv_source
echo "export DEVKIT=$current_path/../.."                                     >> $myenv_source
echo ''                                                                      >> $myenv_source
cat  $current_path/envs/myenv.source.base                                    >> $myenv_source

cp $current_path/* $myenv_home -fr
rm $myenv_home/setup.sh




# 2 prepare myenv command
grep_result=$(grep -F "# MYENV ENV" ~/.bashrc)
if [ "$grep_result" == "" ]; then
    echo "创建环境变量alias快捷方式: me "
    echo "# MYENV ENV" >> ~/.bashrc
    echo "alias me='source $myenv_home/myenv.source'" >> ~/.bashrc
fi




# 3 prepare suc command
echo "echo: alias suc='su - carrot' >> /root/.bashrc"

echo "source ~/.bashrc"

echo "finish"
